# coding:utf-8
# @Author: Mercur1o
# @Software: PyCharm
# @File : exerc1.py
# @Time: 2024/3/5 9:53
import random
def guess_number():
    # 预设一个0-9之间的随机整数
    secret_number = random.randint(0, 9)
    # 初始化猜测次数
    attempts = 0

    while True:
        try:
            # 用户输入猜测的数字
            guess = int(input("请输入一个0-9之间的整数: "))
            # 猜测次数加1
            attempts += 1

            if guess == secret_number:
                print(f"你猜了{attempts}次，猜对了，真厉害！")
                break
            elif guess < secret_number:
                print("你猜的数字小于正确答案")
            else:
                print("你猜的数字大于正确答案")
        except ValueError:
            print("请输入一个有效的整数！")


# 调用猜数字游戏函数
guess_number()
